1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.webmacro.directive;
24
25 import org.webmacro.Context;
26 import org.webmacro.FastWriter;
27 import org.webmacro.PropertyException;
28 import org.webmacro.engine.BuildContext;
29 import org.webmacro.engine.BuildException;
30 import org.webmacro.engine.Variable;
31
32 import java.io.IOException;
33 /***
34 * Implements a directive supporting a global value.
35 */
36 public class GlobalDirective extends Directive
37 {
38
39 private static final int GLOBAL_TARGET = 1;
40
41 private static final ArgDescriptor[]
42 myArgs = new ArgDescriptor[]{
43 new LValueArg(GLOBAL_TARGET),
44 };
45
46 private static final DirectiveDescriptor
47 myDescr = new DirectiveDescriptor("global", null, myArgs, null);
48
49 public static DirectiveDescriptor getDescriptor ()
50 {
51 return myDescr;
52 }
53
54 public Object build (DirectiveBuilder builder,
55 BuildContext bc)
56 throws BuildException
57 {
58 Variable target = null;
59
60 try
61 {
62 target = (Variable) builder.getArg(GLOBAL_TARGET, bc);
63 }
64 catch (ClassCastException e)
65 {
66 throw new NotVariableBuildException(myDescr.name, e);
67 }
68 if (!target.isSimpleName())
69 throw new NotSimpleVariableBuildException(myDescr.name);
70
71 bc.setVariableType(target.getName(), Variable.LOCAL_TYPE);
72 return null;
73 }
74
75 public void write (FastWriter out, Context context)
76 throws PropertyException, IOException
77 {
78 }
79
80 }